﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.APP.Application.Command.Deepprocessings;
using Traceability.Damoin;
using Traceability.ErrorCode;

namespace Traceability.APP.Controllers
{
    /// <summary>
    /// 深加工控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeepprocessingsController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
      /// <summary>
      /// 注释
      /// </summary>
        private readonly IMediator mediator;

        public DeepprocessingsController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取班组表
        /// </summary>
        /// <returns>123</returns>
        [HttpGet]
        public async Task<APIResult<List<Deepprocessing>>> GetDeepprocessings([FromQuery] GetDeepprocessingCommand command)
        {
            try
            {
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        /// <summary>
        /// 班组新增
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> AddDeepprocessing(AddDeepprocessingCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 班组修改
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateDeepprocessing(UpdateDeepprocessingCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取企业表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<MachiningEnterprise>>> GetMachiningEnterprise([FromQuery] GetMachiningEnterpriseCommand command)
        {
            try
            {
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        /// <summary>
        /// 企业新增
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> AddMachiningEnterprise(AddMachiningEnterpriseCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 企业修改
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateMachiningEnterprise(UpdateMachiningEnterpriseCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
